﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CIT.WMS.houseWork.Bll;
using CIT.WMS.houseWork.Model;
using CIT.WMS.houseWork.Helper;
namespace CIT.WMS.houseWork
{
    public partial class FrmDJBarCode : Form
    {
        public FrmDJBarCode()
        {
            InitializeComponent();
        }
        /////// <summary>
        /////// 条码实体
        /////// </summary>
        //BarcodeUtils obj = new BarcodeUtils();

        /// <summary>
        /// 单据号管理实体
        /// </summary>
        T_CustomerReturn_Manage t_obj = new T_CustomerReturn_Manage();

        private void txt_barCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                //BarcodeUtils.BarObject barobj = obj.AnalysisBarcode(Utils.AnalysisSerPath, txt_barCode.Text);
                DataTable dt_BarCode = Bll_CustomerReturn_Manage.Query_Storage(txt_barCode.Text.Trim());
                if (dt_BarCode.Rows.Count > 0)
                {
                    if (dt_BarCode.Rows[0][0].ToString() == "0")
                    {
                        lab_msg.Text = dt_BarCode.Rows[0][1].ToString();
                        lab_msg.ForeColor = Color.Red;
                        txt_barCode.Focus();
                        txt_barCode.SelectAll();
                        return;
                    }

                    t_obj.Qty = SqlInput.ChangeNullToString(dt_BarCode.Rows[0]["Qty"]);
                    //2.生成单据号
                    string DocNum = Bll_CustomerReturn_Manage.CreateDocNum(SqlInput.ChangeNullToString(dt_BarCode.Rows[0]["PartNumber"]));
                    t_obj.Doc_Number = DocNum;//单据号
                    t_obj.ReelID = txt_barCode.Text.Trim();//ReelID
                    t_obj.Creator = Utils.uContext.UserNamek__BackingField;
                    t_obj.Status = "0";
                    t_obj.MaterialNum = SqlInput.ChangeNullToString(dt_BarCode.Rows[0]["PartNumber"]);
                    Bll_CustomerReturn_Manage.Insert(t_obj);
                    //3.冻结操作库存表中对应的sn的物料需要冻结
                    Bll_CustomerReturn_Manage.Action_Update_VStorage("2", new List<string> { txt_barCode.Text.Trim() });
                    t_obj = new T_CustomerReturn_Manage();
                    txt_barCode.SelectAll();
                    lab_msg.Text = "冻结成功.";
                    txt_barCode.Focus();
                    txt_barCode.SelectAll();
                }
                else
                {
                    lab_msg.Text = "料卷不存在.";
                    lab_msg.ForeColor = Color.Red;
                    txt_barCode.Focus();
                    txt_barCode.SelectAll();
                    return;
                }
            }
        }

        private void btn_close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}